bloonsconceptionfandomcom-20200215-history
User blog:Logo12/Lua Templating GET!
So yeah. 3 hours after I requested the Lua thing, it is activated! Hereby I will post a list of the Lua lessons I took in the documentary. Hello World Script Here is how the Lua Templating works: (I myself is a newbie at Lua too so...) First, a page with Module Namespace. Module:LuaExample Then, have a code thing pasted in. For now I'll paste the example given in the documentary. local p = {} function p.hello( frame ) return "Hello, world!" end return p Then, to make it work, put a and...: Script error Script Error! Lol Just kidding. Because for the code, a "hello" parameter is needed. To put a parameter, it is just like how templates works: Now let's try again! Yay it worked! Parameter Script I have to complain that the Reference Manual is NOT helpful at all as there are something more important not even mentioned a bit in the manual. Luckily I got help from User:Shining-Armor and learnt how this works. para = {} function para.meter( frame ) return "You used" .. frame.args1 .. "as parameter." end return para Okay, remember the "frame" thing? that is where arguments (parameters) are stored. It must be frame, no exceptions, and to put arguments we simply .args1 it. Results: What if we didn't put an argument in? Script error Since the argument isn't added, we can't have an empty variable connected to a string. There is a fix to this though. para = {} function para.meter( frame ) if frame.args1 then return "You used" .. frame.args1 .. "as parameter." else return "Error: No Parameters Provided" end end return para That uses a if test to see if the value of frame.args is empty. As a noob of this programming language, this is the best I can do. Now to the next script. Value Type Script After learning something useful, here we come back the so "complete" reference manual (which was mostly copied from the original Lua site). So yeah. The second thing being taught is the Value Type, which is obviously simple for me. "There are 8 types of values, but only 6 are relevant to the Scribunto". And... Nil This is the basic one. If you name a variable, then it is a nil. If you use nil on most functions, it errors (Useful exception being the "if" thing I've used). If you use transferal functions on inappropriate values, it will be nil. So this is basically a "Doesn't exists" value. Number This value type is also simple. Just a signed long variable, which goes to rounding at some point, and not restricted to being integers (floating point). val = {} function val.isnum( frame ) if tonumber(frame.args1) then return frame.args1 .. " is a valid number" else return frame.args1 .. " is not a valid number" end end function val.simpleisnum( frame ) return frame.args1 .. ( tonumber(frame.args1) and " is a valid number" or " is not a valid number" ) end return val This simple(?) test shows if the input is a valid number. To test: More about the functions will be explained later. String Self-explanatory. Only thing that matters are the 2 types of string notation. One of the is the normal "quote" you all are familiar with, one is called the "literal" string, that will call out any slashes, quotations, and stuff which are needed to be escaped with a \. It is notated by the "Link" like thing ([﻿this﻿]), or for advanced matching, you can also add =s in between ([ This ], or even [ as long you remember the number of =s ]) val = {} function val.string ( frame ) return "Use " .. " to concatenate strings and \n for a new line!" end function val.litstring ( frame ) return Use " .. " to concatenate strings and \n for a new line! end return val So yeah, that's simply the thing. Boolean Another simple thing, but with a bit change if you know other programming languages already. Unlike other language things, Only nil, and the false boolean are considered false, while 0 is still a "true" thing. And yeah, that's why the number test works. You insert a string, it will turn into nil if you don't use a number, and nil returns false in the "if". Table Or what we call "Array". Simply like that, except that there are something more about it. Unlike normal arrays, Strings, Booleans, Functions, or even the Table itself can be an index of the table. Functions Well, just a first-class value type that can be done with anything to it. That's all basically. So... Category:Blog posts